import java.io.InputStream;
import java.io.IOException;
import java.util.StringTokenizer;

final class MyBufferedReader {
    private InputStream in;

    public MyBufferedReader (InputStream in) {
        this.in = in;}

    public String readLine () throws IOException {
        final StringBuffer sb = new StringBuffer(80);
        int                i  = 0;
        while (((i = in.read()) != '\n') && (i != -1))
            if (i != '\r')
                sb.append((char) i);
        if (i == -1)
            return null;
        return sb.toString();}}


final class main {
   
   static int [][] ballot;
   static int max;
   static int min;
   static int casenum;
   static int numvoters;
   static String card;
   static int x;
   static int y;
   static boolean end;
   static boolean firstround;
   static int temp;
   
   static String [] candidatesnam;
   
   static int[] votecount;
   static int cannum; 
private static final MyBufferedReader in = new MyBufferedReader(System.in);
   
   
   
   public static void main (String[] args) 
   { 
      
      

      
      
         try {casenum = Integer.parseInt(in.readLine());}
             catch (IOException e){}
            try {in.readLine();}
             catch (IOException e){}
           ballot = new int[1000][21];
             candidatesnam  = new String [21];            
      while(casenum > 0)
      {
         firstround = true;
         max =0; min = 1000;
         try {StringTokenizer st = new StringTokenizer(in.readLine());
             cannum = Integer.parseInt(st.nextToken());
         }
         catch (IOException e) {
            }
         
            
        
        temp = cannum+1;
        votecount = new int [temp];
      
         
      
         
      
       for(int z =1;  z<=cannum;++z )
       {
          try {candidatesnam[z] = in.readLine();}
           catch (IOException e) {}
         
       }
        
       
       
       y = 0;
       end = false;       
       card = "";
       numvoters =0; 
       try {card = in.readLine();}
           catch (IOException e) {end = true;}
           if(card == null||card.length() == 0)
           {end = true;}
            if(!end)
            {
       while ( !end)
         {
          ++numvoters; 
          StringTokenizer st = new StringTokenizer(card);
               for(int z = 1; z <=cannum;++z )
            {ballot[y][z] = Integer.parseInt(st.nextToken());
            
            ballot[y][0]= 1;
            }
           
             ++y;
             
             try {card = in.readLine();}
                 catch (IOException e) {
                     end = true;}
                 if(card == null||card.length() == 0)
                 {end = true;}
                 
             
         }      
      
       while(eval())          {
          firstround = false;}
      
       }
            else{ 
               for(int z = 1; z < cannum+1;z++)
              {   
             System.out.println(candidatesnam[z]);
              }
               
                }  
            if(casenum > 1)
         {
      
         }
       -- casenum; 
      
         
      }
      
      
      
      
   }
   
   public static boolean eval()
   { 
    

       y =0;
      
      while( y<numvoters)
         {
         if (firstround)
         {
            ++votecount[ballot[y][1] ];
            
         }
         
      else if( votecount[ballot[y][ballot[y][0]]]<0)
          {
           while(votecount[ballot[y][ballot[y][0]]]<0)
            {++ballot[y][0];
           }
             ++votecount[ballot[y][ballot[y][0]] ];
          }
          
          ++y;
          }
   
      
       min = 1000;
         for(int z = 1; z<= cannum;z++)
         {
            if( votecount[z] > max)
            max = votecount[z];
         if((votecount[z]<min) && (votecount[z]!= -1))
            min = votecount[z];
            
            
         }
   
         
   
         
         if(max>numvoters/2)
         {y = 0;
               while(votecount[y] != max)
               {++y;}
               System.out.println(candidatesnam[y]);
               return false;
            }
         else if (max == min)
            { for(int z = 1; z < (cannum+1);z++)
               {
                 if(votecount[z] == max)
                    System.out.println(candidatesnam[z]);
               }         
           return false;
           }
     
    
   
    for(int z = 0; z < votecount.length;z++)
    {
       if(votecount[z] == min)
          votecount[z] = -1;
    }
    
    return true;
   }
   
   
}

